package design;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;

import logik.Hotel;
import logik.Hotelverwaltung;
import logik.Tester;
import logik.Testerverwaltung;

public class TesterJList extends JFrame implements ActionListener
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		JPanel panel1 = new JPanel();
		JPanel panel2 = new JPanel();
		JPanel panel3 = new JPanel();
		private JButton abbrechen;
		public Testerverwaltung testerverwaltung;
		public Hotelverwaltung hotelver;
		private DefaultListModel<Tester> model = new DefaultListModel<>();
		


		
		private int y=150;
		private int x=650;
		
		public TesterJList(Testerverwaltung tv)
		{
			testerverwaltung=tv;
			//hotelver=htv;
			initComponents();
			setSize(600,450);
			setLocationRelativeTo(null);
			this.setVisible(true);
			setTitle("Tester");
			setResizable(false);
			setLocation(x,y);
			abbrechen.addActionListener(this);
			aktualisieren();
		}
		
		public TesterJList(ArrayList<Tester> getliste) 
		{
			
		}

		public void aktualisieren()
		{
			model.clear();
			for(Tester t: testerverwaltung.getliste())
			{
				model.addElement(t);
			}
		}

		private void initComponents() 
		{
			final Container c = this.getContentPane();
			c.setLayout(new BorderLayout());
			c.setBackground(Color.CYAN);
			
			panel1 = new JPanel();
			panel1.setBorder(new EmptyBorder(5, 5, 0, 0));
			panel1.setLayout(new BorderLayout(0, 0));
			c.add(panel1);
			//setTitle("TesterJList");
			
			
			JScrollPane scrollPane = new JScrollPane();
			final JList<Tester> list = new JList<Tester>(model);
			scrollPane.setViewportView(list);
			panel1.add(scrollPane, BorderLayout.CENTER);
			
			list.addMouseListener(new MouseAdapter(){
				public void mouseClicked(MouseEvent e) {
			        if (e.getClickCount()==2) 
			        {
			        	System.out.println("DoubleClicked");
			        	HotelJList jl = new HotelJList(hotelver);

			        	
			        }
			       }
			});

			
			
			abbrechen = new JButton("abbrechen");
			panel1.add(panel2, BorderLayout.SOUTH);
			panel2.add(panel3);
			
			panel3.setLayout(new GridLayout(0,2));
			//panel3.setBackground(Color.BLACK);
			panel3.add(abbrechen);
			
		}
		

		public DefaultListModel<Tester> getmodellist()
		{
			return model;
		}
		
		
	
	





		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			JButton source= (JButton)arg0.getSource();
			
			if(source==abbrechen)
			{
				dispose();
			}
			
				

				
			
		}

	}
